home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
os2
/
srefv12i.zip
/
aliaschk.rxx
< prev
next >
Wrap
Text File
|
1996-12-14
|
6KB
|
271 lines
/* Check aliases module for SRE-FILTER. Uses contents of aliasfile
To call: set queue/sempahore with:
newqueue,newsem,OLDURL
Returns
match , newurl
If match=0. then no match (and newurl=oldurl)
*/
parse upper arg aliasfile, usequeue , USESEM, max_semwait
call pmprintf(' SRE-FILTER alias thread: aliasfile='||aliasfile)
call pmprintf(' SRE-FILTER alias thread: queue='||usequeue)
call pmprintf(' SRE-FILTER alias thread: semaphore='||usesem)
mytid=dostid()
call pmprintf(' SRE-FILTER alias thread: thread id='||mytid)
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-FILTER alias thread: initialization ERROR: '||usequeue)
exit
end
call set_alias(aliasfile)
/*
call pmprintf(' aliases ')
do mm=1 to naliases
call pmprintf(aliases.mm)
end
*/
if naliases=0 then do
call pmprintf(' SRE-FILTER alias thread: Warning: No valid entries in alias file:'||aliasfile)
end
else do
call pmprintf(' SRE-FILTER alias thread: #aliases= '||naliases)
end
/* Initialization now done == start waiting for requests for alias info */
signal on error name iserror
signal on syntax name iserror
bakme:
a=rxqueue('s',usequeue)
aq=queued()
if aq=0 then do
WOW=EVENTSEM_WAIT(USESEM,max_semwait)
aq=-1
if wow=640 then do
signal bakme
end
IF WOW<>0 THEN do /* FATAL ERROR */
call call pmprintf(' SRE-FILTER alias thread: fatal semaphore error ')
exit
end
end
wow=EVENTSEM_RESET(usesem)
if aq=-1 then
if queued()=0 then signal bakme
PARSE pull isit0
isit0=translate(isit0,' ','000d0a09'x)
if isit0="" then signal bakme
/* die command? */
if abbrev(isit0,'*DIE*')=1 then
exit
parse var isit0 idnum ',' newq ',' newsem ',' ISIT
parse var idnum idnum host_nickname
isitorig=isit
if newq="" | newsem="" then do
call pmprintf(' SRE-FILTER alias thread: missing queue or semaphore ')
signal bakme
end
newq=upper(strip(newq)); newsem=upper(strip(newsem))
ISIT=STRIP(ISIT)
if abbrev(isit,'*RESET*') then do
parse var isit foo newfile .
if newfile<>' ' then aliasfile=newfile
call set_alias(aliasfile)
call pmprintf(' SRE-Filter alias thread: Reread aliases file: 'aliasfile)
end
else do
if naliases=0 then do
dog1=' 0 '||isitorig
end
else do
isit=translate(isit,'\','/')
isit=strip(isit,'l','\')
dog1=fig_alias(isit,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror:
signal off error ; signal off syntax
call pmprintf(' SRE-FIlter: error in alias thread ')
a=rxqueue('d',usequeue)
a=rxqueue('c',usequeue)
a=eventsem_close(usesem)
a=eventsem_create(usesem)
a=rxqueue('s',newq)
push idnum ', 0 '
wow=eventsem_post(newsem)
call pmprintf('SRE-FIlter: done resetting alias thread ')
signal on error name iserror
signal on syntax name iserror
signal bakme
exit
/* ---------- */
fig_alias:procedure expose aliases. aliashosts.
parse arg inline , host_nickname
host_nickname=strip(upper(host_nickname))
sel=translate(inline,' ','000d0a09'x)
doexact=0
gotit=0
starat=0 ; afterstar=0
do m=1 to aliases.0
if host_nickname<>aliashosts.m & aliashosts.m<>' ' then do
iterate
end
jlias=aliases.m
parse var jlias jlias1 jlias2
ares=sref_wildcard(sel,jlias,doexact)
parse var ares astat "," aurl ; astat=strip(astat)
if astat=0 then iterate /* no match */
aurl=strip(aurl)
if aurl="" then do
usesel0=sel
end
else do
usesel0=aurl
end
if astat=1 then do
usesel=usesel0
gotit=m
leave /*first exact match rules */
end
else do /* best match rules */
t1=pos('*',jlias1)
t33=length(jlias1)-t1
if t1 >= starat then do
if t1 > starat | t33>afterstar then do
starat=t1 ; afterstar=t33
gotit=m
usesel=usesel0
end
end
end
end
if gotit=0 then
usesel=inline
/* fix up / */
parse var usesel k1 '?' k2
k1=translate(k1,'/','\')
if pos('?',usesel)>0 then
usesel=k1||'?'||k2
else
usesel=k1
return gotit ' ' usesel
/* ---------------- */
/* read and set up aliases */
set_alias:
parse arg afile
naliases=0
aliases.0=0
a=fileread(afile,'ulines',,'E') /* read it to a stem variable */
foo=do_extends(1)
oo=stream(afile,'c','close')
if a=0 then do
call pmprintf(' SRE-FILTER alias thread: ERROR reading user-file: '||afile)
return
end
exton=0
do mm=1 to ulines.0
t1=strip(ulines.mm)
if exton=1 then do
t1=t1storage||t1
end
exton=0
if t1="" then iterate
if abbrev(t1,';')=1 then iterate
if right(t1,2)=' ,' & mm < ulines.0 then do
exton=1
t1=left(t1,length(t1)-2)
t1storage=strip(t1)
iterate
end
tm1=strip(word(t1,1)) ; ahost=' '
if right(tm1,2)='//' then do
ahost=upper(left(tm1,length(tm1)-2))
parse var t1 foo t1a t1b
end
else
parse var t1 t1a t1b
t1a=translate(t1a);
t1a=translate(t1a,'\','/')
t1a=strip(t1a,'l','\')
naliases=naliases+1
aliases.naliases=upper(t1a)||' '||t1b
aliashosts.naliases=ahost
end
aliases.0=naliases
return 0
/************/
/* Redo ulines, by treating lines starting with , as continuation lines */
do_extends:procedure expose ulines.
if ulines.0=0 then return
isnew=1
tmps.1=ulines.1
do mm=2 to ulines.0
ali=strip(ulines.mm)
if abbrev(ali,',')=0 then do
isnew=isnew+1
tmps.isnew=ulines.mm
end
else do
tmps.isnew=tmps.isnew||substr(ali,2)
end
end
do mm=1 to isnew
ulines.mm=tmps.mm
end
ulines.0=isnew
return 0